import 'package:enjoy_plus/pages/login/index.dart';
import 'package:enjoy_plus/pages/notice/index.dart';
import 'package:enjoy_plus/pages/profile/index.dart';
import 'package:enjoy_plus/pages/tab_bar_page.dart';
import 'package:enjoy_plus/utils/token.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      routes: {
        '/': (context) => const TabBarPage(),
        '/detail': (context) => const NoticeDetail(),//跳转到详情页
        '/login': (context) => const LoginPage(),
        '/profile': (context) => const ProfilePage(),
      },
      initialRoute: '/',
// 生成动态路由
      onGenerateRoute: (settings) {
        // print(settings);
        // 跳转时判断token是否存在，
        // 1.获取token
        final token = TokenManager().getToken();
        // 2.不存在则跳转到登录页
        if (token == null) {
          return MaterialPageRoute(builder: (context) => const LoginPage());
        }
        // 3.存在则正常跳转
        else if (settings.name == '/profile') {
        return MaterialPageRoute(builder: (context) => const ProfilePage());
      }

      return null;
      },

    ),
  );
// git 测试
// 跨越处理



}